<?php

namespace builder\tree_table\util\tttfilter;

/**
 * 单选
 */
class Radio implements FilterControlInterface
{
    private $_options = [
        'control' => 'radio',
        'label' => '',
        'labelIsHtml' => false,
        'default' => '',
        'options' => [],
        'style' => '',
        'class' => '',
        'attribute' => '',
        'help' => '',
        'unspread' => false,
    ];

    /**
     * 控件标签
     * @param string $label
     * @return $this
     */
    public function label($label)
    {
        $this->_options['label'] = (string)$label;
        return $this;
    }

    /**
     * 标签是否是HTML
     * @return $this
     */
    public function labelIsHtml()
    {
        $this->_options['labelIsHtml'] = true;
        return $this;
    }

    /**
     * 默认值
     * @param string $default
     * @return $this
     */
    public function defaultValue($default)
    {
        $this->_options['default'] = (string)$default;
        return $this;
    }

    /**
     * 选项
     * @param array $options
     * @return $this
     */
    public function options(array $options)
    {
        $this->_options['options'] = $options;
        return $this;
    }

    /**
     * @param string|array $style CSS样式
     * @return $this
     */
    public function style($style)
    {
        $this->_options['style'] = $style;
        return $this;
    }

    /**
     * @param string|array $class CSS类
     * @return $this
     */
    public function uiClass($class)
    {
        $this->_options['class'] = $class;
        return $this;
    }

    /**
     * @param array|string $attribute HTML标签属性
     * @return $this
     */
    public function attribute($attribute)
    {
        $this->_options['attribute'] = $attribute;
        return $this;
    }

    /**
     * 帮助文字
     * @param string $help
     * @return $this
     */
    public function help($help)
    {
        $this->_options['help'] = (string)$help;
        return $this;
    }

    /**
     * 折叠控件
     * @return $this
     */
    public function unspread()
    {
        $this->_options['unspread'] = true;
        return $this;
    }

    /**
     * 数组输出
     * @return array
     */
    public function _toArray()
    {
        $attributes = $this->_options['attribute'];
        if (is_string($attributes)) {
            $attributes .= ' lay-skin="none"';
        } else {
            $attributes['lay-skin'] = 'none';
        }

        $this->_options['attribute'] = $attributes;

        return $this->_options;
    }
}